import { request } from '../request';

export function registerUser(user: any) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/register',
    method: 'post',
    data: user
  });
}

export function deleteUser(userId: number) {
  return request<Api.Auth.LoginToken>({
    url: `/auth/deleteUser/${userId}`,
    method: 'delete'
  });
}

export function registerFaceInfo(data: any) {
  return request<Api.Auth.LoginToken>({
    url: '/register',
    method: 'post',
    data,
    baseURL: 'http://localhost:8000'
  });
}

export function addFaceInfo() {
  return request<Api.Auth.LoginToken>({
    url: '/auth/addFaceInfo',
    method: 'post'
  });
}

export function deleteBatchUser(userIds: number[]) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/deleteBatchUser',
    method: 'delete',
    data: userIds
  });
}

/**
 * Login
 *
 * @param userName User name
 * @param password Password
 */
export function fetchLogin(userId: number, userName: string, password: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/login',
    method: 'post',
    data: {
      userId,
      userName,
      password
    }
  });
}

export function fetchLoginByUserId(userId: number) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/loginByUserId',
    method: 'get',
    params: { userId }
  });
}

/** Get user info */
export function fetchGetUserInfo() {
  return request<Api.Auth.UserInfo>({ url: '/auth/getUserInfo' });
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchRefreshToken(refreshToken: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/refreshToken',
    method: 'post',
    data: {
      refreshToken
    }
  });
}

/**
 * return custom backend error
 *
 * @param code error code
 * @param msg error message
 */
export function fetchCustomBackendError(code: string, msg: string) {
  return request({ url: '/auth/error', params: { code, msg } });
}
